package kr.ac.mju.mdc.mjuapp.notice;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

import kr.ac.mju.mdc.mjuapp.R;
import kr.ac.mju.mdc.mjuapp.http.HttpManager;
import kr.ac.mju.mdc.mjuapp.network.NetworkManager;
import kr.ac.mju.mdc.mjuapp.util.PixelConverter;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;

import android.app.Activity;
import android.app.Dialog;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author davidkim
 *
 */
public class NoticeListActivity extends Activity implements OnClickListener, OnItemClickListener, OnTouchListener {
	private final int PROGRESS_DIALOG = 10;
	private final int LOADING_SUCCESS = 11;
	private final int LOADING_FAIL = 12;
	private final int SLIDING_MOVE_LEFT = 13;
	private final int SLIDING_MOVE_RIGHT = 14;

	private String listUrl;

	private NoticeAdapter noticeAdapter;
	private ArrayList<Notice> noticeList;
	private ArrayList<String> pagingUrlList;

	private int prevLastPositionOfNoticeList = 0;
	// subTitle(general= 0, ... , bid = 6)
	private int currentSubTitle = 0;

	private boolean isOpened = false;

	private int leftMax = 0;
	private int leftMin = 0;

	private float oldX = 0;
	private float upOldX = 0;

	private Timer slidingTimer = null;
	private TimerTask slidingTimerTask = null;
	/**********************************************************
	 *  
	 **********************************************************/
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			int what = msg.what;
			switch (what) {
			case LOADING_SUCCESS:
				// get tag element list
				HashMap<String, List<Element>> elementMap = (HashMap<String, List<Element>>) msg.obj;
				List<Element> tbodyElementsList = elementMap.get(HTMLElementName.TBODY);
				List<Element> pageElementsList = elementMap.get(HTMLElementName.DIV);
				// parsing paging list
				if (pageElementsList != null && pagingUrlList.size() == 0)
					parsingPagingList(pageElementsList);
				// parsing article list
				if (pagingUrlList.size() > 0) {
					if (tbodyElementsList != null)
						parsingNoticeList(tbodyElementsList);
				} else if (pagingUrlList.size() == 0) {
					if (tbodyElementsList.size() > 0)
						parsingNoticeList(tbodyElementsList);
				}
				// dismissdialog
				dismissDialog(PROGRESS_DIALOG);
				// init ListView top of the noticeList
				((ListView) findViewById(R.id.notice_list_listview)).setSelection(prevLastPositionOfNoticeList);
				// set preview last position of Article list
				// because of offering recent list by clicking 'load more'
				prevLastPositionOfNoticeList = noticeList.size();
				break;
			case LOADING_FAIL:
				// dismissdialog
				dismissDialog(PROGRESS_DIALOG);
				// error weak signal msg
				Toast.makeText(getApplicationContext(), getResources().getString(R.string.msg_network_error_weak_signal),
						Toast.LENGTH_SHORT).show();
				break;
			case SLIDING_MOVE_LEFT:
				slidingTimer = new Timer();
				slidingTimerTask = new TimerTask() {
					@Override
					public void run() {
						// TODO Auto-generated method stub
						handler.post(new Runnable() {
							@Override
							public void run() {
								// TODO Auto-generated method stub
								View contentView = findViewById(R.id.notice_list_content);
								// right to left
								if (contentView.getLeft() <= leftMin) {
									contentView.layout(0, contentView.getTop(), contentView.getRight(), contentView.getBottom());
									stopSlidingTimer();
									oldX = 0;
									upOldX = 0;
									isOpened = false;
									findViewById(R.id.notice_list_left_slidingbar).setClickable(false);
								} else {
									contentView.layout(contentView.getLeft() - 15, contentView.getTop(), contentView.getRight() - 15,
											contentView.getBottom());
								}
							}
						});
					}
				};
				slidingTimer.schedule(slidingTimerTask, 0, 5);
				break;
			case SLIDING_MOVE_RIGHT:
				slidingTimer = new Timer();
				slidingTimerTask = new TimerTask() {
					@Override
					public void run() {
						// TODO Auto-generated method stub
						handler.post(new Runnable() {
							@Override
							public void run() {
								// TODO Auto-generated method stub
								View contentView = findViewById(R.id.notice_list_content);
								// to right
								if (contentView.getLeft() >= leftMax) {
									contentView.layout(leftMax, contentView.getTop(), leftMax + contentView.getRight(),
											contentView.getBottom());
									stopSlidingTimer();
									oldX = 0;
									upOldX = 0;
									isOpened = true;
									findViewById(R.id.notice_list_left_slidingbar).setClickable(true);
								} else {
									contentView.layout(contentView.getLeft() + 15, contentView.getTop(), contentView.getRight() + 15,
											contentView.getBottom());
								}
							}
						});
					}
				};
				slidingTimer.schedule(slidingTimerTask, 0, 5);
				break;
			}
		}
	};

	/**********************************************************
	 *  
	 **********************************************************/
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notice_list_layout);
		//init
		init();
		//init layout
		initLayout();
		// init listView
		initListView();
		// showlist
		if (NetworkManager.checkNetwork(NoticeListActivity.this))
			showListFromPost();
		// set subtitle click listener
		setSubtitleClickListener();
		// set search btn listener
		((ImageButton) findViewById(R.id.notice_list_search_btn)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (NetworkManager.checkNetwork(NoticeListActivity.this))
					onSearchRequested();
			}
		});
		findViewById(R.id.notice_list_sliding_btn).setOnTouchListener(this);
		findViewById(R.id.notice_list_left_slidingbar).setOnTouchListener(this);
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		switch (id) {
		case PROGRESS_DIALOG:
			Dialog progressDialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
			progressDialog.setContentView(R.layout.loading_progress);
			progressDialog.setCancelable(false);
			return progressDialog;
		default:
			return null;
		}
	}

	@Override
	protected void onNewIntent(Intent intent) {
		// TODO Auto-generated method stub
		setIntent(intent);
		if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
			String keyword = intent.getStringExtra(SearchManager.QUERY);
			searchKeyword(keyword.trim());
		}
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		if (isOpened)
			handler.sendEmptyMessage(SLIDING_MOVE_LEFT);
		else
			super.onBackPressed();
	}

	/**
	 * 게시판 글 목록 ListView 초기화
	 */
	private void initListView() {
		// set adapter
		noticeAdapter = new NoticeAdapter(getApplicationContext(), noticeList);
		ListView generalNoticeListView = (ListView) findViewById(R.id.notice_list_listview);
		generalNoticeListView.setAdapter(noticeAdapter);
		generalNoticeListView.setOnItemClickListener(this);
		noticeAdapter.notifyDataSetChanged();

		// set load next page listener
		((TextView) findViewById(R.id.notice_list_more)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (NetworkManager.checkNetwork(NoticeListActivity.this)) {
					if (pagingUrlList.size() > 0) {
						listUrl = pagingUrlList.get(0);
						pagingUrlList.remove(0);
						showListFromPost();
					} else
						Toast.makeText(getApplicationContext(), getResources().getString(R.string.msg_load_more_last), Toast.LENGTH_SHORT)
								.show();
				}
			}
		});
	}

	/**
	 * 게시판 글 목록 POST 요청
	 */
	private void showListFromPost() {
		showDialog(PROGRESS_DIALOG);
		Thread thread = new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				// create httpManager
				HttpManager httpManager = new HttpManager();
				// init
				httpManager.init();
				// set httpPost
				httpManager.setHttpPost(listUrl);
				// httpResponse
				HttpResponse response = null;
				// execute
				try {
					response = httpManager.executeHttpPost();
					// get Status
					StatusLine status = response.getStatusLine();
					if (status.getStatusCode() == HttpStatus.SC_OK) {
						// html response result
						HttpEntity entity = response.getEntity();
						// parsing element
						Vector<String> tagNames = new Vector<String>();
						tagNames.add(HTMLElementName.TBODY);
						tagNames.add(HTMLElementName.DIV);
						// parse result
						HashMap<String, List<Element>> elementMap = httpManager.getHttpElementsMap(entity, tagNames);
						// send result to handler
						Message msg = handler.obtainMessage();
						msg.what = LOADING_SUCCESS;
						msg.obj = elementMap;
						handler.sendMessage(msg);
					} else
						handler.sendEmptyMessage(LOADING_FAIL);
				} catch (ClientProtocolException e) {
					// TODO Auto-generated catch block
					handler.sendEmptyMessage(LOADING_FAIL);
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					handler.sendEmptyMessage(LOADING_FAIL);
					e.printStackTrace();
				} finally {
					httpManager.shutdown();
				}
			}
		});
		thread.start();
	}

	/**
	 * 게시판 글 목록 파싱
	 * 
	 * @param elementList
	 */
	private void parsingNoticeList(List<Element> elementList) {
		// get <tr> tags
		List<Element> trList = elementList.get(0).getAllElements(HTMLElementName.TR);

		for (Element trElement : trList) {
			// <tr> 1개의 6개의 <td>
			List<Element> tdList = trElement.getAllElements(HTMLElementName.TD);
			Notice notice = new Notice();
			boolean itHasNumber = true;
			// 세부 글 목록 정보 파싱
			for (int index = 0; index < tdList.size(); index++) {
				// 글 번호
				if (index == 0) {
					String num = tdList.get(index).getContent().toString().trim();
					/*
					 * 공지로 최상위 리스트에 올라와있는 경우, 실제 게시목록에도 중복 등록되어 있다. 이전 구현 버전에서는,
					 * 이것도 리스트에 포함시켰는데, '공지' 목록이 많을 경우, load more을 해도 계속 중복되서
					 * 리스트에 포함되는 경우가 발생한다. '공지'는 리스트에서 제외
					 */
					if (num.contains("<img")) {
						itHasNumber = false;
						break;
					}
					// 등록된 게시물이 없을 경우, return 처리
					else if (num.contains(getResources().getString(R.string.msg_no_list))) {
						Toast.makeText(getApplicationContext(), getResources().getString(R.string.msg_no_list), Toast.LENGTH_SHORT).show();
						return;
					}
					notice.setA_num(num);
				}
				// 글 번호가 있을 경우만 파싱
				if (itHasNumber) {
					// 제목
					if (index == 1) {
						Element aElement = tdList.get(index).getFirstElement(HTMLElementName.A);
						String subject = aElement.getContent().toString().trim();
						String url = aElement.getAttributeValue("href").trim();
						if (subject.contains("</a>"))
							subject = subject.substring(0, subject.indexOf("</a>"));
						else if (subject.equals(""))
							subject = "제목없음";
						if (url == null)
							url = "";
						notice.setA_subject(subject);
						notice.setA_url(url);
					}
					// 날짜
					else if (index == 2) {
						String date = tdList.get(index).getContent().toString().trim();
						if (date == null)
							date = "작성일자정보없음";
						notice.setA_date(date);
					}
					// 첨부파일 여부
					else if (index == 4) {
						String attachFile = tdList.get(index).getContent().toString();
						if (attachFile != null) {
							if (attachFile.contains("<img"))
								notice.setA_file(true);
							else
								notice.setA_file(false);
						}
					}
				}
			}
			// 글번호가 있을경우만 추가
			if (itHasNumber)
				noticeList.add(notice);
		}
		noticeAdapter.notifyDataSetChanged();
	}

	/**
	 * 게시판 하단 페이징 넘버 파싱
	 * 
	 * @param elementList
	 */
	private void parsingPagingList(List<Element> elementList) {
		// get <div> element
		List<Element> divList = elementList.get(0).getAllElements(HTMLElementName.DIV);

		for (Element divElement : divList) {
			// get <div class="paging"> element
			String attr = divElement.getAttributeValue("class");
			if (attr != null) {
				if (attr.trim().equals("paging")) {
					// get <strong> element to find current page
					Element strongElement = divElement.getFirstElement(HTMLElementName.STRONG);
					String currentPage = strongElement.getContent().toString().trim();
					if (currentPage != null) {
						// get <a> element list
						List<Element> aList = divElement.getAllElements(HTMLElementName.A);
						// get nextPages
						for (Element aElement : aList) {
							String content = aElement.getContent().toString().trim();
							// 처음 목록 이동, 이전 목록으로 이동은 제외시킨다
							// 다음 목록으로 이동과, 마지막 목록으로 이동만 포함한다
							// 다음 목록으로 이동이 있을 경우 , 마지막 목록으로 이동은 포함시키지 않는다
							if (content.startsWith("<img")) {
								String title = aElement.getAttributeValue("title").trim();
								if (title.startsWith("다음")) {
									String url = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/" + aElement.getAttributeValue("href").trim();
									pagingUrlList.add(url);
									break;
								}
							}
							// 페이지 넘버의 경우, 현재 페이지 보다 높은 페이지만 포함시킨다
							else if (Integer.valueOf(content) > Integer.valueOf(currentPage)) {
								String url = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/" + aElement.getAttributeValue("href").trim();
								pagingUrlList.add(url);
							}
						}
					}
					/**** if (currentPage != null) ******/
				}
			}
		}
	}

	/**
	 * 게시판 subtitle clickListener
	 */
	private void setSubtitleClickListener() {
		((TextView) findViewById(R.id.notice_subtitle_general)).setOnClickListener(this);
		((TextView) findViewById(R.id.notice_subtitle_event)).setOnClickListener(this);
		((TextView) findViewById(R.id.notice_subtitle_grade)).setOnClickListener(this);
		((TextView) findViewById(R.id.notice_subtitle_bachelor)).setOnClickListener(this);
		((TextView) findViewById(R.id.notice_subtitle_scholarship)).setOnClickListener(this);
		((TextView) findViewById(R.id.notice_subtitle_job)).setOnClickListener(this);
		((TextView) findViewById(R.id.notice_subtitle_bid)).setOnClickListener(this);
	}

	/**
	 * 게시판 subTitle 선택 시, 이벤트 처리
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id = v.getId();
		// checkNetwork
		if (NetworkManager.checkNetwork(this)) {
			String title = "";
			switch (id) {
			case R.id.notice_subtitle_general:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11294&id=mjukr_050101000000";
				title = "일반공지";//getResources().getString(R.string.title_notice_general);
				currentSubTitle = 0;
				break;
			case R.id.notice_subtitle_event:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11302&id=mjukr_050102000000";
				title = "행사공지";//getResources().getString(R.string.title_notice_event);
				currentSubTitle = 1;
				break;
			case R.id.notice_subtitle_grade:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11310&id=mjukr_050103000000";
				title = "성적/수강공지";//getResources().getString(R.string.title_notice_grade);
				currentSubTitle = 2;
				break;
			case R.id.notice_subtitle_bachelor:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11318&id=mjukr_050104000000";
				title = "기타학사공지";//getResources().getString(R.string.title_notice_bachelor);
				currentSubTitle = 3;
				break;
			case R.id.notice_subtitle_scholarship:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11327&id=mjukr_050106000000";
				title = "장학/학자금공지";//getResources().getString(R.string.title_notice_scholarship);
				currentSubTitle = 4;
				break;
			case R.id.notice_subtitle_job:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11366&id=mjukr_050107000000";
				title = "경력/취업공지";//getResources().getString(R.string.title_notice_job);
				currentSubTitle = 5;
				break;
			case R.id.notice_subtitle_bid:
				listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=15103&id=mjukr_050105000000";
				title = "입찰공지";//getResources().getString(R.string.title_notice_bid);
				currentSubTitle = 6;
				break;
			}
			if (isOpened)
				handler.sendEmptyMessage(SLIDING_MOVE_LEFT);
			// clear list
			initList();
			// show list
			showListFromPost();
			// change main title
			((TextView) findViewById(R.id.notice_maintitle)).setText("");
			((TextView) findViewById(R.id.notice_maintitle)).setText(title);
		}
	}

	/**
	 * 게시판 글 검색
	 * 
	 * @param keyword
	 */
	private void searchKeyword(String keyword) {
		// set post url
		listUrl = "http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?";

		switch (currentSubTitle) {
		// general
		case 0:
			listUrl += "qt=&boardId=11294&listType=01&id=mjukr_050101000000&column=TITLE&search=" + keyword;
			break;
		// event
		case 1:
			listUrl += "qt=&listType=01&column=TITLE&boardId=11302&id=mjukr_050102000000&search=" + keyword;
			break;
		// grade
		case 2:
			listUrl += "qt=&listType=01&column=TITLE&boardId=11310&id=mjukr_050103000000&search=" + keyword;
			break;
		// bachelor
		case 3:
			listUrl += "qt=&listType=01&column=TITLE&boardId=11318&id=mjukr_050104000000&search=" + keyword;
			break;
		// scholarship
		case 4:
			listUrl += "qt=&listType=01&column=TITLE&boardId=11327&id=mjukr_050106000000&search=" + keyword;
			break;
		// job
		case 5:
			listUrl += "qt=&listType=01&column=TITLE&boardId=11366&id=mjukr_050107000000&search=" + keyword;
			break;
		// bid
		case 6:
			listUrl += "qt=&listType=01&column=TITLE&boardId=15103&id=mjukr_050105000000&search=" + keyword;
			break;
		}
		// clear list
		initList();
		// showList
		showListFromGet();
		// setMainTitle
		((TextView) findViewById(R.id.notice_maintitle)).setText("");
		((TextView) findViewById(R.id.notice_maintitle)).setText(getResources().getString(R.string.title_search));
	}

	/**
	 * 글 목록 데이터 초기화
	 */
	private void initList() {
		// clear list
		noticeList.clear();
		pagingUrlList.clear();
		noticeAdapter.notifyDataSetChanged();
		prevLastPositionOfNoticeList = 0;
	}

	/**
	 * 게시판 글 목록 GET 요청
	 */
	private void showListFromGet() {
		// showDialog
		showDialog(PROGRESS_DIALOG);
		Thread thread = new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				// create httpManager
				HttpManager httpManager = new HttpManager();
				// init
				httpManager.init();
				// set httpGet
				httpManager.setHttpGet(listUrl);
				// httpResponse
				HttpResponse response = null;
				// execute
				try {
					response = httpManager.executeHttpGet();
					// get Status
					StatusLine status = response.getStatusLine();
					if (status.getStatusCode() == HttpStatus.SC_OK) {
						// html response result
						HttpEntity entity = response.getEntity();
						// parsing element
						Vector<String> tagNames = new Vector<String>();
						tagNames.add(HTMLElementName.TBODY);
						tagNames.add(HTMLElementName.DIV);
						// parse result
						HashMap<String, List<Element>> elementMap = httpManager.getHttpElementsMap(entity, tagNames);
						// send result to handler
						Message msg = handler.obtainMessage();
						msg.what = LOADING_SUCCESS;
						msg.obj = elementMap;
						handler.sendMessage(msg);
					} else
						handler.sendEmptyMessage(LOADING_FAIL);
				} catch (ClientProtocolException e) {
					// TODO Auto-generated catch block
					handler.sendEmptyMessage(LOADING_FAIL);
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					handler.sendEmptyMessage(LOADING_FAIL);
					e.printStackTrace();
				} finally {
					httpManager.shutdown();
				}
			}
		});
		thread.start();
	}

	/**
	 * 게시판 글 선택 시, 글 세부내용 보기 위한 이벤트 처리
	 * 
	 * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView,
	 *      android.view.View, int, long)
	 */
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(NoticeListActivity.this, NoticeViewActivity.class);
		intent.putExtra("url", noticeList.get(position).getA_url());
		intent.putExtra("subtitle", ((TextView) findViewById(R.id.notice_maintitle)).getText().toString());
		startActivity(intent);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		if (event.getAction() == MotionEvent.ACTION_MOVE) {
			float currentX = event.getRawX();
			if (oldX == 0.)
				oldX = currentX;
			// drag
			View view = findViewById(R.id.notice_list_content);
			if (view.getLeft() <= leftMax && view.getLeft() >= leftMin) {
				view.layout((int) (view.getLeft() - (oldX - currentX)), view.getTop(), (int) (view.getRight() - (oldX - currentX)),
						view.getBottom());
				upOldX = oldX;
				oldX = currentX;
			}
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			final float currentX = event.getRawX();
			// direction
			float direction = upOldX - currentX;
			if (isOpened)
				handler.sendEmptyMessage(SLIDING_MOVE_LEFT);
			else if (!isOpened)
				handler.sendEmptyMessage(SLIDING_MOVE_RIGHT);
			else if (direction > 0)
				handler.sendEmptyMessage(SLIDING_MOVE_LEFT);
			else if (direction < 0)
				handler.sendEmptyMessage(SLIDING_MOVE_RIGHT);
		}
		return false;
	}

	/**
	 * 
	 */
	private void init() {
		// init url //general notice url
		listUrl = new String("http://www.mju.ac.kr/mbs/mjukr/jsp/board/list.jsp?boardId=11294&id=mjukr_050101000000");
		// set pageUrlList
		pagingUrlList = new ArrayList<String>();
		// set list posting
		noticeList = new ArrayList<Notice>();
		//
		isOpened = false;
		oldX = 0;
		upOldX = 0;
		DisplayMetrics displaymetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
		PixelConverter converter = new PixelConverter(this);
		leftMax = (int) ((float)displaymetrics.widthPixels - converter.getWidth(135));
		leftMin = 0;
	}
	/**
	 * 
	 */
	private void initLayout(){
		PixelConverter converter = new PixelConverter(this);
		RelativeLayout.LayoutParams rParams = null;
		rParams = (LayoutParams) findViewById(R.id.notice_sub_layout).getLayoutParams();
		rParams.rightMargin = converter.getWidth(135);
		findViewById(R.id.notice_sub_layout).setLayoutParams(rParams);
	}

	/**
	 * 
	 */
	private void stopSlidingTimer() {
		if (slidingTimerTask != null) {
			slidingTimerTask.cancel();
			slidingTimerTask = null;
		}
		if (slidingTimer != null) {
			slidingTimer.purge();
			slidingTimer.cancel();
			slidingTimer = null;
		}
	}
}
/* end of file */